home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / linux / tools / amiga / gzip-1.1.2.lha / gzip-1.1.2 / zforce.in < prev    next >
Encoding:
Text File  |  1993-05-27  |  920 b   |  41 lines

  1. :
  2. #!/bin/sh
  3. # zforce: force a gz extension on all gzip files so that gzip will not
  4. # compress them twice.
  5. #
  6. # This can be useful for files with names truncated after a file transfer.
  7. # 12345678901234 is renamed to 12345678901.gz
  8.  
  9. x=`basename $0`
  10. if test $# = 0; then
  11.   echo "force a '.gz' extension on all gzip files"
  12.   echo usage: $x files...
  13.   exit 1
  14. fi
  15.  
  16. res=0
  17. for i do
  18.   if test ! -f "$i" ; then
  19.     echo ${x}: $i not a file
  20.     res=1
  21.     continue
  22.   fi
  23.   test `expr "$i" : '.*[.-]z$'` -eq 0 || continue
  24.   test `expr "$i" : '.*[.-]gz$'` -eq 0 || continue
  25.   test `expr "$i" : '.*[.]t[ag]z$'` -eq 0 || continue
  26.  
  27.   gzip -t "$i" 2>/dev/null || continue
  28.  
  29.   if test `expr "$i" : '^............'` -eq 12; then
  30.     new=`expr "$i" : '\(.*\)...$`.gz
  31.   else
  32.     new="$i.gz"
  33.   fi
  34.   if mv "$i" "$new" 2>/dev/null; then
  35.     echo $i -- replaced with $new
  36.     continue
  37.   fi
  38.   res=1; echo ${x}: cannot rename $i to $new
  39. done
  40. exit $res
  41.